$(function () {
  var bdobj = {}
  $('.denglu').on('click', function () {
    const bdstrs = $('#form1').serialize().split('&')
    for (var i = 0; i < bdstrs.length; i++) {
      const start = bdstrs[i].substr(0, bdstrs[i].indexOf('='))
      const end = bdstrs[i].substr(bdstrs[i].indexOf('=') + 1, bdstrs[i].length)
      bdobj[start] = end
    }
    axios({
      method: 'POST',
      url: 'http://big-event-vue-api-t.itheima.net/api/login',
      data: bdobj,
    })
      .then(({ data: res }) => {
        if (res.code !== 0) {
          alert('用户名或密码错误')
        } else {
          alert('登录成功')
          localStorage.setItem('xtxtoken', res.token)
          location.href = './index.html'
        }
      })
      .catch((error) => {
        console.log(error)
      })
  })
})
